<?php include ("../../core/function.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi">
<head>
	<!-- Assign Theme name -->
	
	<!-- Title and meta -->
    <meta http-equiv="content-language" content="vi" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
	
<script type="text/javascript" src="../../../js/jquery-1.3.2.js"></script>
	<script type="text/javascript" src="../../../js/tooltip.js"></script>
	
	<script type="text/javascript" src="http://tamnguyen.gencrm.com/include/common.js"></script>

    <!-- Sheet Css -->
	<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="style.css">
   
    <link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="../../../skins/css/formstyle.css" />
	
	<!-- Javascript -->
 
    <!-- customized header contents -->
	<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<script type="text/javascript" src="../../../js/core.js">
</script>
<script type="text/javascript" src="../../../js/popup_customer.js">
</script>
<script type="text/javascript" src="../../../js/xajax_core.js" charset="UTF-8"></script>
</script>
	<script type="text/javascript">
 
  	var JSTRAN = {language:{"_LANGCODE":"vi","_YES":"Yes","_NO":"No","_OK":"\u0110\u1ed3ng \u00fd","_CANCEL":"H\u1ee7y b\u1ecf","_PLEASEWAIT":"Please Wait","_FETCHING":"Loading...","_TAKINGBACK":"Taking you back to where you were....","_US_LOGGEDOUT":"B\u1ea1n \u0111\u00e3 tho\u00e1t kh\u1ecfi h\u1ec7 th\u1ed1ng","_LOGOUT":"Logout","_SUBJECT":"Subject","_ADD":"Add","_EDIT":"Edit","_DELETE":"X\u00f3a","_CLOSE":"Close","_SUBMIT":"Submit","_NOPERM":"B\u1ea1n ch\u01b0a \u0111\u01b0\u1ee3c quy\u1ec1n truy c\u1eadp v\u00e0o khu v\u1ef1c n\u00e0y.","_ERRORS":"Errors","_SEARCH":"Search","_ALL":"All","_TITLE":"Title","_OPTIONS":"Options","_LOGIN":"User Login","_USERNAME":"Username: ","_PASSWORD":"Password: ","_SELECT":"Select","_IMAGE":"Image","_SEND":"Send","_ASCENDING":"Ascending order","_DESCENDING":"Descending order","_BACK":"Back","_CONFIRM":"X\u00e1c nh\u1eadn","_GENCRM_URL":"http:\/\/tamnguyen.gencrm.com","_ERROR_OCCURED":"C\u00f3 l\u1ed7i x\u1ea3y ra","_ALERT_CHUA_CHON_KH":"B\u1ea1n ch\u01b0a ch\u1ecdn kh\u00e1ch h\u00e0ng n\u00e0o"}}
  	</script>  	
</head>
<body  >
<div id="wrr-body-main">
<div class="wrr-body">
<div class="wrr-body-r">

<div style="width:100%; overflow: hidden">

	  <table class="wrr-content" cellpadding="0" cellspacing="0" style="margin-top:0px;clear: both">
    <tr>
	
	<td id="centercolumn">


		<!-- Start content module page -->
		<div id="content"><style>
#content{
    background:#ffffff;
    height: 800px;
}
</style>
<div  style="display:block; margin-right:170px;" id="timkiem">
	 <form id="frmSearch" method="post" action="">
<div>
	<input type="hidden" name="flag" value="1" />
	<input type="hidden" name="popup_email" value="" />
	<input type="hidden" name="dmll" value="1" />
	<input type="hidden" name="dvi" value="56" />
</div>
<div id="divFrmSearch" class="searchFrm" style="display:block;width:730px;float:left;margin-left:25px;margin-right:25px;text-align:center;">
<img src="../../../skins/images/search_20x20.png" align="absmiddle"><b>Tìm kiếm khách hàng</b>
	<div class="row1">
		<div class="col-left-per-50">
			<div class="col-left-per-30" style="text-align:right; padding-right: 8px;">Tên khách hàng</div>
			<div class="col-left-auto" style="text-align:right; padding-right: 8px;">
            	<input type="text" name="name_kh" value="<?php echo $_POST['name_kh'];?>" size="30"/>
            </div>
		</div>
		<div class="col-left-per-50">
			<div class="col-left-per-30" style="text-align:right; padding-right: 8px;">Cá nhân/ tổ chức</div>
			<div class="col-left-auto" style="text-align:right; padding-right: 8px;">
				<select name="canhan">
					<option value="">Lựa chọn</option>
					<option value="1"<?php if($_POST['canhan']==1){?> selected="selected" <?php }?>>Cá nhân</option>
					<option value="2"<?php if($_POST['canhan']==2){?> selected="selected" <?php }?>>Tổ chức</option>
				</select>
			</div>
		</div>
		<div class="col-left-per-50">
			<div class="col-left-per-30" style="text-align:right; padding-right: 8px;">Loại khách hàng</div>
			<div class="col-left-auto">
				<select name="loaikhachhang">
					<option value="">Lựa chọn</option>
                    <?php 
						$sqlstring="select services_type_name,services_type_id  from tb_services_type where phanloai_id=16 order by services_type_id asc";									
					$qr12=mysql_query($sqlstring);	
					while($row=mysql_fetch_array($qr12)) 
					{	
					?>
					<option  value="<?php echo $row['services_type_id'];?>" <?php if($_POST['loaikhachhang']==$row['services_type_id']){?> selected="selected" <?php }?>>
						<?php echo $row['services_type_name']?>
                    </option>
                    <?php }?>
				</select>
			</div>
		</div>
	</div>
	<div class="row1">
		
		<div class="col-left-per-50">
			<div class="col-left-per-30" style="text-align:right; padding-right: 8px;"> Lĩnh vực hoạt động </div>
			<div class="col-left-auto">
				<select name="linhvuchoatdong" style="width:206px;">
					<option value="">Lựa chọn</option>
					 <?php 
					$sqlstring="select services_type_name,services_type_id  from tb_services_type where phanloai_id=18 order by services_type_id asc";									
					$qr12=mysql_query($sqlstring);	
					while($row=mysql_fetch_array($qr12)) 
					{				
  					?>               
                 <option  value="<?=$row['services_type_id']?>" <?php if($_POST['linhvuchoatdong']==$row['services_type_id']){?> selected="selected" <?php }?>>
				 	<?=$row['services_type_name']?>
                 </option>
                  <?php }?>  
                    
				</select>	
			</div>
		</div>
	</div>
	<div class="row1" style="clear:both;text-align: center;">
			<input type="submit" value="Tìm kiếm" name="search" class="save" />
			<input type="reset" value="Làm lại" class="save" />
	</div>
</div>
</form>
</div>
	<div id="header1" style="margin-top:15px; width:730px;float:left;">
	</div>
	
<div style="width:735px;margin-left:25px;">
		<form id="form" method="post" action="">
		<div>
			<input type="hidden" name="action" id="action" value="delete" />
			<input type="hidden" name="sort" id="sort" value="" />
			<input type="hidden" name="type" id="type" value="" />
			<input type="hidden" name="cur_id" id="cur_id" value="0" />
			<input type="hidden" name="cur_name" id="cur_name" value="" />
			<input type="hidden" name="name" value="" />
			<input type="hidden" name="canhan" value="0" />
			<input type="hidden" name="trangthai" value="" />
			<input type="hidden" name="loaikhachhang" value="" />
			<input type="hidden" name="linhvuchoatdong" value="" />
			<input type="hidden" name="dvi" value="56" />
		</div>
		<div class="tableHead" style="overflow:hidden;">
				
				<div  class="firstCol" style="width:40%;text-align:left;padding-left:5px;">
							<b>Tên khách hàng</b>
				</div>
				<div  class="Cols" style="width:30%; text-align:left;padding-left:5px;">
					<b>Cá nhân/ tổ chức</b>
				</div>
				<div  class="Cols" style="width:24.8%;text-align:left;padding-left:5px;float:right;">
					<b>Loại khách hàng</b>
				</div>
		</div>
        <?php 
			$name_kh=$_POST['name_kh'];
			$canhan=$_POST['canhan'];
			$loaikhachhang=$_POST['loaikhachhang'];
			$linhvuchoatdong=$_POST['linhvuchoatdong'];
		?>
        <?php 
			$sqlstring="select
							id,
							name_kh,
							name_com,
							loai_kh,
							area,
							object 
						from 
							customers ";
			if($name_kh!="" and $canhan=="" and $loaikhachhang=="" and $linhvuchoatdong=="")
			{
				$sqlstring.="where name_kh like '%$name_kh%' or name_com like '%$name_kh%'";
			}
			if($name_kh!="" and $canhan!="" and $loaikhachhang=="" and $linhvuchoatdong=="")
			{
				$sqlstring.="where (name_kh like '%$name_kh%' or name_com like '%$name_kh%') and object='$canhan'";
			}
			if($name_kh!="" and $canhan!="" and $loaikhachhang!="" and $linhvuchoatdong=="")
			{
				$sqlstring.="where (name_kh like '%$name_kh%' or name_com like '%$name_kh%') and object='$canhan' and loai_kh='$loaikhachhang'";
			}
			if($name_kh!="" and $canhan!="" and $loaikhachhang!="" and $linhvuchoatdong!="")
			{
				$sqlstring.="where (name_kh like '%$name_kh%' or name_com like '%$name_kh%') and object='$canhan' and loai_kh='$loaikhachhang' and 			 								area='$linhvuchoatdong'";
			}
			if($name_kh=="" and $canhan!="" and $loaikhachhang=="" and $linhvuchoatdong=="")
			{
				$sqlstring.="where object='$canhan'";
			}
			if($name_kh=="" and $canhan!="" and $loaikhachhang!="" and $linhvuchoatdong=="")
			{
				$sqlstring.="where object='$canhan' and loai_kh='$loaikhachhang'";
			}
			if($name_kh=="" and $canhan!="" and $loaikhachhang!="" and $linhvuchoatdong!="")
			{
				$sqlstring.="where object='$canhan' and loai_kh='$loaikhachhang' and area='$linhvuchoatdong'";
			}
			if($name_kh=="" and $canhan=="" and $loaikhachhang=="" and $linhvuchoatdong!="")
			{
				$sqlstring.="where area='$linhvuchoatdong'";
			}
			if($name_kh=="" and $canhan=="" and $loaikhachhang!="" and $linhvuchoatdong=="")
			{
				$sqlstring.="where loai_kh='$loaikhachhang'";
			}
			if($name_kh=="" and $canhan=="" and $loaikhachhang!="" and $linhvuchoatdong!="")
			{
				$sqlstring.="where loai_kh='$loaikhachhang' and area='$linhvuchoatdong'";
			}
			if($name_kh=="" and $canhan!="" and $loaikhachhang=="" and $linhvuchoatdong!="")
			{
				$sqlstring.="where object='$canhan' and area='$linhvuchoatdong'";
			}
			$sql_kh=mysql_query($sqlstring);
			$i=0;
			$n_record=mysql_num_rows($sql_kh); 
			while($row_kh=mysql_fetch_array($sql_kh))
			{
		?>
		<div style="overflow:hidden;"  ondblclick="select_pro(<?php echo $row_kh['id'];?>, '<?php if($row_kh['object']==1){echo $row_kh['name_kh'];}else{echo $row_kh['name_com'];}?>'); submit_pp_select();" id="prorow_<?php echo $i++;?>" class="row01" onclick="select_pro(<?php echo $row_kh['id'];?>, '<?php if($row_kh['object']==1){echo $row_kh['name_kh'];}else{echo $row_kh['name_com'];}?>'); select_row('prorow', this, <?php echo $n_record;?>, 'row01', 'row02');">
						
						<div  class="firstCol" style="width:40%;text-align:left;padding-left:5px;"><?php if($row_kh['object']==1){echo $row_kh['name_kh'];}else{echo $row_kh['name_com'];}?></div>
						<div  class="Cols" style="width:30%; text-align:left;padding-left:5px;"> 
							<?php if($row_kh['object']==1){echo 'Cá nhân';}?>
                            <?php if($row_kh['object']==2){echo 'Tổ chức';}?>
                        </div>
						<div  class="Cols" style="width:24.8%;text-align:left;padding-left:5px;float:right">
                        <?php 
							$sql_lkh=mysql_query("select services_type_name,services_type_id  from tb_services_type where phanloai_id=16 and 
													services_type_id='".$row_kh['loai_kh']."'");
							$rs_lkh=mysql_fetch_array($sql_lkh);
						?>
						<?php echo $rs_lkh['services_type_name'];?>
                        <span style="display:none;" id="ttdm_<?php echo $row_kh['id'];?>">
							<select id="Dml_Id" name="Dml_Id" style="width:300px">
								<option value="">Lựa chọn</option>
                                <?php $sql_dmll=mysql_query("select id,name,khachhang_id from daumoilienlac where khachhang_id='".$row_kh['id']."'");
								while($row_dmll=mysql_fetch_array($sql_dmll))
								{
								?>
                                <option value="<?php echo $row_dmll['id'];?>"><?php echo $row_dmll['name'];?> </option>
                                <?php }?>
							</select>
						</span>
						<span style="display:none;" id="ttch_<?php echo $row_kh['id'];?>">
							<select id="Chb_Id" name="Chb_Id" style="width:300px">
								<option value="">Lựa chọn</option>
                                <?php $sql_chbh=mysql_query("select id,name,kh_id,dmll_id from cohoi where kh_id='".$row_kh['id']."'");
								while($row_chbh=mysql_fetch_array($sql_chbh))
								{
								?>
                                <option value="<?php echo $row_chbh['id'];?>"><?php echo $row_chbh['name'];?> </option>
                                <?php }?>
							</select>
						</span>
                        </div>	
		</div>
        <?php }?>
						<div style="width:100%; float:left; height:10px; text-align:left; border:none">&nbsp;</div>
<br /><br />

        <div class="row2" style="margin-top:5px">
            <div style="float:left;margin-left:5px;"><input type="button" value="Chọn" onclick="submit_pp_select();" class="save" />
                    <input type="button" value="Hủy bỏ" onclick="close_popup();" class="save" /></div>
            </form>	
        	</div>
		</div>
	</div>

	</td>

	</tr>
</table>

</div>
</div>
</div>
</div>
</body>
</html>